package com.qf.oa_system.service.impl;

import com.qf.oa_system.entity.*;
import com.qf.oa_system.mapper.ClassesDao;
import com.qf.oa_system.mapper.HeadStudentMapper;
import com.qf.oa_system.mapper.StudentDao;
import com.qf.oa_system.service.HeadStudentService;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import java.util.List;

/**
 * 查询学生信息
 */
@Service
public class HeadStudentServiceimpl implements HeadStudentService {

    @Resource
    private HeadStudentMapper headStudentMapper;

    @Resource
    private ClassesDao classesDao;

    @Resource
    private StudentDao studentDao;

    /**
     * 查询学生
     *
     * @return
     */
    @Override
    public List<StudentsAndClasses> queryStudentByTyp() {
        List<StudentsAndClasses> students = headStudentMapper.queryStudentByTab();
        return students;
    }

    /**
     * 查询所有tab为2的学生
     *
     * @param leaveTab
     * @return
     */
    @Override
    public List<StudentsAndLeaves> queryLeavesByTab(int leaveTab) {
        List<StudentsAndLeaves> leaves = headStudentMapper.queryLeavesByTab(leaveTab);
        return leaves;
    }

    /**
     * 同意申请操作
     *
     * @param leaveId
     * @return
     */
    @Override
    public int success(int leaveId) {
        int i = headStudentMapper.success(leaveId);
        return i;
    }

    /**
     * 查询准备导出的学生信息
     *
     * @return
     */
    @Override
    public StudentsAndClasses queryStudentByStuId(int one) {


            StudentsAndClasses students = headStudentMapper.queryStudentByStuId(one);

//        //输出
//        try {
//            //获取桌面
//            FileSystemView fsv = FileSystemView.getFileSystemView();
//            File file1 = fsv.getHomeDirectory();
//
//            String string = UUID.randomUUID().toString();
//            String str1 = string.substring(0, 7);
//            //生成文件
//            File file2 = new File(file1.getPath() +File.separator +"学生信息表"+str1+".xls");
////            if (!file2.exists()){
////                file2.mkdir();
////            }
//            FileOutputStream file = new FileOutputStream(file2);
//            hssfWorkbook.write(file);
//            file.close();
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }





        return students;
    }


    /**
     * 导入学生信息
     * @param studentsAndClasses
     * @return
     */

    @Override
    public int insertStudentsByExcel(StudentsAndClasses studentsAndClasses) {
        //
        Classes classes = classesDao.queryClassesByName(studentsAndClasses.getClassName());

        Student student = new Student();
        student.setStuName(studentsAndClasses.getStuName());
        student.setStuBirthday(studentsAndClasses.getStuBirthday());
        student.setStuAddress(studentsAndClasses.getStuAddress());
        student.setClassId(classes.getClassId());
        student.setStuPhone(studentsAndClasses.getStuPhone());
        student.setStuSex(studentsAndClasses.getStuSex());
        student.setUserId(2);

        int insert = studentDao.insert(student);
        return insert;
    }

    @Override
    public List<WeeklyStudents> queryWeeklyStudents() {
        List<WeeklyStudents> weeklyStudents = headStudentMapper.queryWeeklyStudents();
        return weeklyStudents;
    }

    @Override
    public StudentsSS queryStudentsSS(int sId) {

        StudentsSS students = headStudentMapper.queryStudentsSS(sId);

        return students;
    }
}
